package top.goldenyear.porpoise.system.setting.controller.admin;

import lombok.extern.slf4j.Slf4j;
import org.noear.solon.annotation.*;
import top.goldenyear.porpoise.common.core.model.Ret;
import top.goldenyear.porpoise.framework.web.core.controller.BaseController;
import top.goldenyear.porpoise.framework.web.core.model.query.QPage;
import top.goldenyear.porpoise.system.setting.dto.DictItemSearchReq;
import top.goldenyear.porpoise.system.setting.model.DictItem;
import top.goldenyear.porpoise.system.setting.service.DictItemService;

/**
 * 字典数据表 Controller 控制层
 *
 * @author airhead
 * @since 2024-10-15
 */
@Component(tag = "adminApi")
@Mapping("/setting/dictItem")
@Slf4j
public class DictItemAdminController extends BaseController {
  @Inject private DictItemService service;

  @Post
  @Mapping("create")
  public Ret create(@Body DictItem dictItem) {
    return Ret.okWithData(service.createDictItem(dictItem));
  }

  @Post
  @Put
  @Mapping("update")
  public Ret update(@Body DictItem dictItem) {
    return Ret.okWithData(service.updateDictItem(dictItem));
  }

  @Get
  @Mapping("get")
  public Ret get(@Param Integer id) {
    return Ret.okWithData(service.getDictItem(id));
  }

  @Post
  @Delete
  @Mapping("delete")
  public Ret delete(@Param Integer id) {
    return Ret.okWithData(service.deleteDictItem(id));
  }

  @Get
  @Mapping("paginate")
  public Ret paginate(QPage qPage, DictItemSearchReq searchReq) {
    return Ret.okWithData(service.paginateDictItem(qPage, searchReq));
  }

  @Get
  @Mapping("list")
  public Ret list() {
    DictItem dictItem = getBean(DictItem.class);
    return Ret.okWithData(service.listDictItem(dictItem));
  }

  @Get
  @Mapping("simpleList")
  public Ret simpleList() {
    DictItem dictItem = getBean(DictItem.class);
    return Ret.okWithData(service.simpleListDictItem(dictItem));
  }

  @Get
  @Mapping("item")
  public Ret item() {
    DictItem dictItem = getBean(DictItem.class);
    return Ret.okWithData(service.getDictItem(dictItem));
  }

  @Get
  @Mapping("options/{dictCode}")
  public Ret options(@Path String dictCode) {
    return Ret.okWithData(service.options(dictCode));
  }
}
